<div class="modal-body">
    <form class="form">
        <input type="hidden" id="afterSaleId" name="afterSaleId" value="${obj.id}">
        <input type="hidden" id="afterSaleType" name="afterSaleType" value="${obj.applyType}">
        <input type="hidden" id="flag" name="flag" value="${flag}">
        <input type="hidden" id="vouchers" name="vouchers">
        <div class="row mt5">
            <!--#if(flag == 1 || flag == 3){#-->
            <div class="from-group">
                <div class="col-sm-8 col-md-offset-2">${msg['order.after.refundment.confirmReturnMoney']}：</div>
                <div class="col-sm-8 col-md-offset-2">
                    <input id="returnMoney" name="returnMoney" type="text" class="form-control" value="" placeholder="${msg['order.after.main.column.returnMoney']}" >
                </div>
            </div>
            <!--#}#-->
            <div class="form-group">
                <div class="col-sm-8 col-md-offset-2">
                    <input id="note" class="form-control" name="note" placeholder="${msg['order.after.title.placeholderNote']}"/>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-8 col-md-offset-2">
                    <div id="queue"></div>
                    <div>
                        <input id="file_upload" name="file_upload" type="file" multiple="true">
                    </div>
                    <div id="div_img" class="div-img"></div>
                </div>
            </div>
        </div>
    </form>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">${msg['globals.button.cancel']}</button>
    <button type="button" class="btn btn-primary" id="confirm" onclick="sellerHandle(this)">${msg['globals.button.confirm']}</button>
</div>

<script>
    $(document).ready(function () {
        myForm.init();
        // 文件上传
        $('#file_upload').uploadifive(initAlbumOptions());

        $("#opeModal").on("hidden.bs.modal", function () {
            $(this).removeData("bs.modal");
        });
    });

    /**
     * 初始化相册
     */
    function initAlbumOptions() {
        var queueId = "queue";
        var fileuploadId = "file_upload";
        var imgDivIdPrefix = "div_album";
        var albumContainer = document.getElementById("div_img");
        var sort = Sortable.create(albumContainer);
        var imgIndex = $(albumContainer).children().size();
        return {
            'auto': true,
            'multi': true,
            'width': '100%',
            'height': '35',
            'buttonText': "${msg['order.after.title.uploadImgNote']}",
            'fileType': 'image/jpg,image/jpeg,image/png',
            'fileSizeLimit': 1024,
            'queueSizeLimit': 3,
            'removeCompleted':true,
            'removeTimeout':0,
            'formData': {},
            'queueID': queueId,
            'uploadScript': '${base!}/open/file/upload/image',
            'onUploadComplete': function (file, data) {
                data = JSON.parse(data);
                if (data.code == 0) {
                    Toast.success(data.msg);
                    var c = "divImg";
                    imgIndex++;
                    if(imgIndex == 1){
                        c = "divImgD";
                    }
                    var imgDivId = imgDivIdPrefix + imgIndex;
                    $(albumContainer).append("<div id='"+imgDivId+"' class='"+c+"' style='width:100px;'>" +
                        "<img class='uploadImg' src='" + data.data+ "' style='width:100px;height: 80px;margin-bottom: 1px;'><br>" +
                        "<i style='float: right;padding-top: 4px;' class='fa fa-close' onclick=\"delAlbumImg('"+imgDivId+"')\"></i>" +
                        "</div>");
                    sort.destroy();
                    sort = Sortable.create(albumContainer);
                    $("#"+queueId).empty();
                } else {
                    Toast.error(data.msg);
                }
            },
            'onSelect' : function(queue) {
                if($(albumContainer).children().length >= 3){
                    Toast.warning("${msg['order.after.title.uploadImgWarning']}");
                    $("#" + fileuploadId).uploadifive('cancel', $('.uploadifive-queue-item').first().data('file'));
                }
            }
        };
    }

    function delAlbumImg(id){
        $("#"+id).remove();
    }

    // 卖家处理
    function sellerHandle(el) {
        var flag = $("#flag").val();
        var _vouchers = "";
        $("#div_img .uploadImg").each(function () {
            var src = $(this).attr('src');
            _vouchers += src + ",";
        })
        var returnMoney = $("#returnMoney").val();
        if(flag == 1 || flag == 3){
            var reg = /^(([1-9][0-9]+)|([0-9]+\.[0-9]{1,2}))$/;
            if(!reg.test(returnMoney)){
                alert("请正确输入数字(不超过两位小数)！");
                $("#returnMoney").focus();
                return;
            }
        }

        $.post("${base}/store/order/afterSale/sellerHandle", {
            afterSaleId: $("#afterSaleId").val(),
            flag: flag,
            applyType: "${obj.applyType}",
            voucher: _vouchers,
            note: $("#note").val(),
            returnMoney:returnMoney
        }, function (res) {
            if (res.code == 0) {
                Toast.success("${msg['globals.result.success']}");
                $("#opeModal").modal("hide");
                window.location.reload();
            } else {
                Toast.error(res.msg);
            }
        });
    }

</script>
